package com.youku.plugins.endcardV4New.view
{
   import flash.display.Sprite;
   import com.youku.interfaces.IEndCardV4New;
   import com.youku.plugins.PluginEventDispather;
   import com.youku.plugins.endcardV4New.model.data.PlayerSizeData;
   import com.youku.plugins.endcardV4New.model.data.PlayerVideoData;
   import com.youku.plugins.endcardV4New.EndCardConstant;
   
   public class Interaction extends Sprite implements IEndCardV4New
   {
      
      public function Interaction() {
         super();
      }
      
      private var _eventManager:PluginEventDispather;
      
      private var _sizeData:PlayerSizeData;
      
      private var _playerVideoData:PlayerVideoData;
      
      private var _replay:Replay;
      
      private var _share:Share;
      
      private var _up:Up;
      
      private var _favorite:Favorite;
      
      private var _touchFullScreen:TouchFullScreen;
      
      private var _width:Number;
      
      private var _height:Number;
      
      public function init(param1:Object = null, param2:PluginEventDispather = null, param3:PlayerSizeData = null) : void {
         this._playerVideoData = param1 as PlayerVideoData;
         this._eventManager = param2;
         this._sizeData = param3;
         this._replay = new Replay();
         this._replay.init(param1,param2,param3);
         this._share = new Share();
         this._share.init(param1,param2,param3);
         this._up = new Up();
         this._up.init(param1,param2,param3);
         if(this._sizeData.playerType == EndCardConstant.PLAYER_TYPE_TOUCH)
         {
            this._touchFullScreen = new TouchFullScreen();
            this._touchFullScreen.init(param1,param2,param3);
            addChild(this._touchFullScreen);
         }
         else
         {
            this._favorite = new Favorite();
            this._favorite.init(param1,param2,param3);
            addChild(this._favorite);
         }
         addChild(this._replay);
         addChild(this._share);
         addChild(this._up);
      }
      
      public function changeSize(param1:PlayerSizeData = null) : void {
         if(this._sizeData.playerType == EndCardConstant.PLAYER_TYPE_TOUCH)
         {
            this._touchFullScreen.changeSize(param1);
         }
      }
      
      public function uninstall() : void {
         this._replay.uninstall();
         this._share.uninstall();
         this._up.uninstall();
         if(contains(this._replay))
         {
            removeChild(this._replay);
         }
         if(contains(this._share))
         {
            removeChild(this._share);
         }
         if(contains(this._up))
         {
            removeChild(this._up);
         }
         if(this._sizeData.playerType == EndCardConstant.PLAYER_TYPE_TOUCH)
         {
            this._touchFullScreen.uninstall();
            if(contains(this._touchFullScreen))
            {
               removeChild(this._touchFullScreen);
            }
         }
         else
         {
            this._favorite.uninstall();
            if(contains(this._favorite))
            {
               removeChild(this._favorite);
            }
         }
      }
      
      public function setWH(param1:Number, param2:Number) : void {
         this._width = param1;
         this._height = param2;
         this.layout();
      }
      
      private function layout() : void {
         if(this._sizeData.playerType == EndCardConstant.PLAYER_TYPE_TOUCH)
         {
            this._touchFullScreen.x = 0;
            this._touchFullScreen.y = 0;
         }
         else
         {
            this._favorite.x = 0;
            this._favorite.y = 0;
         }
         this._share.x = this._width - this._share.width;
         this._share.y = 0;
         this._up.x = 0;
         this._up.y = this._height - this._up.height;
         this._replay.x = this._width - this._replay.width;
         this._replay.y = this._height - this._replay.height;
      }
   }
}
